/**
 * 工具类
 */
package com.wqr.it.ecwdr.client.util;

import java.text.SimpleDateFormat;
import java.util.Date;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


/**
 * @author adinos
 *
 */
public class DateUtils {
	private static final Logger log = LoggerFactory.getLogger(DateUtils.class);
	private static final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	private static final SimpleDateFormat ssdf = new SimpleDateFormat("yyyyMMddHHmmss");

	public static String format(Date date) {
		String str = null;
		if (date != null) {
			try {
			str = sdf.format(date);
			} catch (Exception e) {
				log.error(e.getMessage());
			}
		} 
		return str;		
	}

	public static String format(Date date, String dateFormat) {
		String str = null;
		if (date != null) {
			try {
			str = new SimpleDateFormat(dateFormat).format(date);
			} catch (Exception e) {
				log.error(e.getMessage());
			}
		} 
		return str;		
	}
	
	/**
	 * 获取当前格式化的日期
	 * @return
	 */
	public static String currentDate() {
		return format(new Date());
	}
	
	/**
	 * 获取当前简短格式化的日期 yyyyMMddHHmmss
	 * @return
	 */
	public static String currentShortDate() {
		return ssdf.format(new Date());
	}

	public static String currentDate(String dateFormat) {
		return new SimpleDateFormat(dateFormat).format(new Date());
	}
}
